package com.sx.zongzhi.fragment;

import android.support.v4.app.Fragment;

/**
 * <pre>
 *     author : XZY
 *     e-mail : xxx@xx
 *     time   : 2017/09/08
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public abstract class LazyFragment extends Fragment {

    protected boolean isVisible;
    /**
     * 在这里实现Fragment数据的缓加载.
     */
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(getUserVisibleHint()) {
            isVisible = true;
            onVisible();
        } else {
            isVisible = false;
            onInvisible();
        }
    }
    @Override public void onDestroy() {
        super.onDestroy();
//        RefWatcher refWatcher = MyApplication.getRefWatcher(getActivity());
//        refWatcher.watch(this);
    }

    /**
     * 可见执行此类
     */
    protected void onVisible(){
        lazyLoad();
    }

    /**
     * 加载数据的类
     */
    protected abstract void lazyLoad();

    /**
     * 不可见加载此类
     */
    protected void onInvisible(){}
}
